package com.ymx.darling.expression;

import java.util.LinkedList;

/**
 * 栈结构
 * @param <E> 数据泛型E
 */
public class LinkedStack<E> {
    private final LinkedList<E> data = new LinkedList<>();

    public boolean isEmpty() {
        return this.data.isEmpty();
    }

    public void push(E elem) {
        this.data.addFirst(elem);
    }

    public E pop() {
        if (this.data.isEmpty()) {
            return null;
        }
        return this.data.removeFirst();
    }

    public E peek() {
        if (this.data.isEmpty()) {
            return null;
        }
        return this.data.getFirst();
    }

    public int size() {
        return this.data.size();
    }
}
